<template>
  <div class="newsItem-box" @click="handleClick(data)">
    <div class="img" :style="{backgroundImage: 'url(' + data.coverUrl + ')'}">
      <div v-if="data.date || data.location"  class="info-box">
        <template v-if="data.date">
          时间：{{formatDate(data.date)}}
        </template>
        <template v-if="data.date&&data.location">
          丨
        </template>
        <template v-if="data.location">
          地点：{{data.location}}
        </template>
      </div>
    </div>
    <div class="title-box">
      <div v-if="data.name" class="title">{{ data.name }}</div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
moment.locale("zh-cn");
export default {
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  methods: {
    handleClick(item) {
      this.$router.push({ name: 'ColumnDetail', query: { uuid: item.uuid } })
    },
    // 处理时间
    formatDate(date) {
      if (!date) {
        return '';
      }
      return moment(date).format("YYYY.MM.DD");
    }
  }
}
</script>

<style lang="scss" scoped>
.newsItem-box {
  width: 380px;
  height: 304px;
  overflow: hidden;
  cursor: pointer;
  .img {
    width: 380px;
    height: 200px;
    display: block;
    transition: all 1s;
    position: relative;
    &:hover {
      transform: scale(1.12);
    }
    .info-box {
      width: 100%;
      background: linear-gradient(-180deg, transparent, rgba(0, 0, 0, 0.65) 97%);
      font-size: 14px;
      text-align: center;
      color: #fff;
      height: 20px;
      line-height: 20px;
      position: absolute;
      left: 0;
      bottom: 0;
      font-family: "Microsoft YaHei", 微软雅黑, "MicrosoftJhengHei";
    }
  }
  .title-box {
    padding: 25px 10px;
    background: #fff;
    .title {
      height: 48px;
      font-size: 18px;
      font-family: "Microsoft YaHei", 微软雅黑, "MicrosoftJhengHei";
      font-weight: bold;
      line-height: 24px;
      box-sizing: border-box;
      color: #000000;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      word-break: break-all;
    }
  }
}
</style>